package com.xuzhiguang.baidu.pan.sdk.token;

import com.xuzhiguang.baidu.pan.sdk.model.OAuthAccessTokenResult;

/**
 * @author xuzhiguang
 * @date 2020/6/26 13:54
 */
public class AccessTokenUtil {

    public static AccessToken convertAccessToken(OAuthAccessTokenResult result) {
        AccessToken accessToken = new AccessToken();
        accessToken.setAccessToken(result.getAccessToken());
        accessToken.setRefreshToken(result.getRefreshToken());
        accessToken.setSessionKey(result.getSessionKey());
        accessToken.setSessionSecret(result.getSessionSecret());
        accessToken.setScopes(result.getScope().split(" "));

        accessToken.setExpiresTime(System.currentTimeMillis() + ((long)result.getExpiresIn() * 1000));

        return accessToken;
    }
}
